﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;

namespace MidSoft
{
    public partial class MidSoft : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            #region 根据查询数据显示数据
            ChinaSoft.BLL.Common.Bind bllBind = new ChinaSoft.BLL.Common.Bind();
            DataSet ds = bllBind.GetDataSet("*", "V_RolePower", "UserAccount='"+ChinaSoft.Common.Input.SetString(Session["UserAccount"])+"' and (PowerId  between 1 and 8) order by Sort,CreateTime desc");
            string result = string.Empty;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                DataTable dt = ds.Tables[0];

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (i < (dt.Rows.Count - 1))
                    {
                        result=GetResult(result, dt.Rows[i]["PowerId"]);
                        result += "<li class=\"line\"></li>";
                    }
                    else if (i == (dt.Rows.Count - 1))
                    {
                        result = GetResult(result, dt.Rows[i]["PowerId"]);
                    }
                }
            }
            #endregion

            #region 判断显示的样式
            //取得模块名称；
            string strTemp = Request.Url.ToString();
            strTemp = strTemp.Substring(0,strTemp.LastIndexOf("/"));
            strTemp=strTemp.Substring(strTemp.LastIndexOf("/")+1);
            //设置相应菜单样式
            switch (strTemp)
            {
                case "Main":
                    result=result.Replace("\"/Main/Main.aspx\"", "\"/Main/Main.aspx\"  class=\"current\" ");
                    break;
                case "WorkFlow":
                    result=result.Replace("\"/WorkFlow/WorkFlow.aspx\"", "\"/WorkFlow/WorkFlow.aspx\"  class=\"current\" ");
                    break;
                case "ProjectInfo":
                    result=result.Replace("\"/ProjectInfo/ProjectInfo.aspx\"", "\"/ProjectInfo/ProjectInfo.aspx\"  class=\"current\" ");
                    break;
                case  "Finance":
                    result=result.Replace("\"/Finance/Finance.aspx\"", "\"/Finance/Finance.aspx\"  class=\"current\" ");
                    break;
                case "Message":
                    result=result.Replace("\"/Message/Message.aspx\"", "\"/Message/Message.aspx\"  class=\"current\" ");
                    break;
                case "Search":
                    result=result.Replace("\"/Search/Search.aspx\"", "\"/Search/Search.aspx\"  class=\"current\" ");
                    break;
                case "Sys":
                    result=result.Replace("\"/Sys/Sys.aspx\"", "\"/Sys/Sys.aspx\"  class=\"current\" ");
                    break;
            }
            #endregion
            literalList.Text = result;
        }

        private string GetResult(string result, object input)
        {
            switch (ChinaSoft.Common.Input.SetInt(input))
            {
                case 2:
                    result += "<li  class=\"li-1\"><a href=\"/Main/Main.aspx\">我的首页</a></li>";
                    break;
                case 3:
                    result += "<li class=\"li-2\"><a href=\"/WorkFlow/WorkFlow.aspx\" >工作流程</a></li>";
                    break;
                case 4:
                    result += "<li class=\"li-3\"><a href=\"/ProjectInfo/ProjectInfo.aspx\">项目信息</a></li>";
                    break;
                case 5:
                    result += "<li class=\"li-4\"><a href=\"/Finance/Finance.aspx\" >财务管理</a></li>";
                    break;
                case 6:
                    result += "<li class=\"li-5\"><a href=\"/Message/Message.aspx\">消息中心</a></li>";
                    break;
                case 7:
                    result += "<li class=\"li-6\"><a href=\"/Search/Search.aspx\">综合查询</a></li>";
                    break;
                case 8:
                    result += "<li class=\"li-7\"><a href=\"/Sys/Sys.aspx\" >系统管理</a></li>";
                    break;
            }
            return result;
        }
    }
}